/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ZhongJinTao
 * Date: 2024-03-22
 * Time: 20:22
 */

/**
 * 371. 两整数之和
 * https://leetcode.cn/problems/sum-of-two-integers/submissions/515376751/
 */
public class Solution2 {
    //位运算，先异或求出无进位之和，再按位与进位是哪一位(a&b)<< 1
    public int getSum(int a, int b) {
        while(((a & b) << 1) != 0) {
            int tmp1 = a ^ b;
            int tmp2 = (a & b) << 1;
            a = tmp1;
            b = tmp2;
        }
        return a ^ b;
    }
}
